package edu.utn.tacs.grupouno.dao;

import java.io.Serializable;
import java.util.UUID;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;


@MappedSuperclass
public abstract class PersistentObject implements Serializable{
	
	private static final long serialVersionUID = -8574384000912913908L;

	@Id
	@XmlAttribute
	private UUID id = UUID.randomUUID();
	
	@Version
	@XmlTransient
	private int version;

	@XmlTransient
	public UUID getId() {
		return id;
	}

	public void setId(UUID id) {
		this.id = id;
	}
	
	@XmlTransient
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PersistentObject that = (PersistentObject) o;

//        return id == that.getId();
        return !(id != null ? !id.equals(that.id) : that.id != null);
    }

    @Override
    public int hashCode() {
    	return id != null ? id.hashCode() : 0;
    }

}
